package main

import (
	"net/http"
	"io"
)

func main() {
	http.HandleFunc("/echo", func(w http.ResponseWriter, req *http.Request) {
		io.WriteString(w, "hello golang!\n")
	})

	http.Handle("/form", http.HandlerFunc(func(w http.ResponseWriter, req *http.Request){
		var username string
		if req.Method=="POST" {
			username=req.FormValue("username")
		}

		html:=`<!DOCTYPE HTML><html>
			<head>
				<title>test title</title>
			</head>
			<body>
				<form method="post">
					<input type="text" name="username" value="` +username+ `" />
					<input type="submit" value="Submit username" />
				</form>
			</body>
		</html>`

		io.WriteString(w, html)
	}))

	http.ListenAndServe("127.0.0.1:3000", nil)
}
